package demo3;

class Animal {
    public String name;
    public int age;

    static {
        System.out.println("Animal的静态代码块。");
    }

    {
        System.out.println("Animal的实例代码块。");
    }

    public Animal() {
        System.out.println("Animal的不带参数的构造方法。");
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("Animal的带两个参数的构造方法。");
    }

    public void eat() {
        System.out.println(this.name + "eat()!");
    }

    public void sleep() {
        System.out.println(this.name + "sleep()!");
    }
}

class Cat extends Animal {

    public String fur;

    static {
        System.out.println("Cat的静态代码块。");
    }

    {
        System.out.println("Cat的实例代码块。");
    }

    public Cat() {
        super(); // 必须放在第一行
        System.out.println("Cat的不带参数的构造方法。");
    }

    public Cat(String name, int age, String fur) {
        super(name, age); // 显示调用父类的构造方法,来初始化子类从父类继承过来的东西
        this.fur = fur; // 一定要先调用父类的构造方法,再完成子类的构造,否则报错
        System.out.println("Cat的带三个参数的构造方法。");
    }

    public void mew() {
        System.out.println(this.name + "cat::mew()!");
    }
}

public class TestDemo {
    public static void main(String[] args) {

        Cat cat1 = new Cat("咪咪", 2, "black");
        System.out.println("==============================");
        Cat cat2 = new Cat("喵喵", 3, "orange");

//        cat.eat();
//        cat.mew();
//        cat.sleep();
    }
}
